<template>
  <div class="login-panpel">
    <!-- 顶部标题-->
    <h1 class="title">后台管理系统</h1>
    <!-- 中级tabs-->
    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <el-tab-pane label="账号登录" name="account">
          <template #label>
            <div class="label">
              <el-icon><UserFilled /></el-icon>
              <span class="text">账号登录</span>
            </div>
          </template>
          <PaneAccount ref="accountRef" />
        </el-tab-pane>
        <el-tab-pane label="手机登录" name="phone">
          <template #label>
            <div class="label">
              <el-icon><Cellphone /></el-icon>
              <span class="text">手机登录</span>
            </div>
          </template>
          <PanePhone />
        </el-tab-pane>
      </el-tabs>
    </div>
    <!-- 底部区域-->
    <div class="controls">
      <el-checkbox v-model="isRemPwd" label="记住密码" size="large" />
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" size="large" @click="submitHandleClick">立即登录</el-button>
  </div>
</template>

<script setup lang="ts">
import { localCache } from '../../../untils/caceh'
import { ref, reactive, watch } from 'vue'
import PaneAccount from './pane-account.vue'
import PanePhone from './pane-phone.vue'
const isRemPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false) // 获取本地存储的 isrempwd
const activeName = ref<String>('account')
const accountRef = ref<InstanceType<typeof PaneAccount>>()

watch(isRemPwd, (newValue) => {
  console.log(newValue)
  localCache.setCache('isRemPwd', newValue)
})

function submitHandleClick() {
  console.log(activeName.value, '--activeName')
  if (activeName.value === 'account') {
    console.log('账号登录')
    // 1. 获取子组件的实例
    accountRef.value?.loginAction(isRemPwd.value)
    // 2. 调用方法
    if (isRemPwd.value) {
      console.log('记住账号密码')
    }
  } else {
    console.log('手机登录')
  }
}
</script>

<style lang="less" scoped>
.login-panpel {
  width: 330px;
}
</style>
